﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace PaceR.Web.MvcModels
{
    public class MvcScript : IDisposable
    {
        private readonly ViewContext _viewContext;
        private bool _tagClosed;

        public MvcScript(ViewContext viewContext)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException("viewContext");
            }

            _viewContext = viewContext;
        }

        public void Dispose()
        {
            EndScript();
        }

        public virtual void EndScript()
        {
            if (!_tagClosed)
            {
                _tagClosed = true;
                MvcScript.EndScript(_viewContext);
            }
        }

        internal static void BeginScript(ViewContext viewContext)
        {
            viewContext.Writer.WriteLine("<script>");
        }

        internal static void EndScript(ViewContext viewContext)
        {
            viewContext.Writer.WriteLine("</script>");
        }
    }
}
